/**
 * Created by zheng on 2018/7/2.
 */
$(function () {
    $('#dg').datagrid({
        url: '/insurancebill/list',
        fit: true,
        fitColumns: true,
        //分页条
        pagination: true,
        // fit:true,
        //工具栏
        toolbar: "#tb",
        //单选
        singleSelect:true,
        columns: [/*[
         {field: 'baseInfo', title: '基本属性', colspan: 2, width: 100, align: "center"},
         {field: 'otherInfo', title: '其他属性', colspan: 3, width: 100, align: "center"}
         ],*/ [
            {field: 'x', checkbox: 'true'},
            {field: 'id', title: '编码', width: 100,hidden:true},
            {field: 'oddNumber', title: '保险单号', width: 100},
            {field: 'car', title: '车牌号', width: 100,formatter:function (v,r,i) {
                    return v? v.number:'';
                }},
            {field: 'applicant', title: '投保人', width: 100,formatter:function (v,r,i) {
                    return v? v.name:'';
                }},
            {field: 'vdate', title: '投保申请日期', width: 100},
            {field: 'auditDate', title: '审核日期', width: 100},
            {field: 'beginDate', title: '起保日期', width: 100},
            {field: 'endDate', title: '止保日期', width: 100},
            {field: 'inputUser', title: '业务员', width: 100,formatter:function (v,r,i) {
                    return v? v.username:"meiyou";
                }},
            {field: 'auditUser', title: '审核人', width: 100,formatter:function (v,r,i) {
                    console.log(v);
                    return v? v.username:'';
                }},
            {field: 'totalPrice', title: '投保总金额', width: 100},
            {field: 'state', title: '状态', width: 100,formatter:function (v,r,i) {
                    if (v==1){
                        return "<font color='orange'>未交费</font>"
                    }else if (v==2){
                        return "<font color='#00bfff'>已投保</font>"
                    }else if(v==3){
                        return "<font color='purple'>待批改</font>"
                    }else if(v==4){
                        return "<font color='red'>拒保</font>"
                    }else if(v==5){
                        return "<font color='pink'>已审核未付款</font>"
                    }else if(v==0){
                        return "<font color='green'>未审核未交费</font>"
                    }else{
                        return "<font color='green'>投保成功</font>"
                    }
                }}
        ]],
        //新增
        border:false,
        cls:"table table-very table-basic"
    })

    //准备输入的对话弹框
    $('#dd').dialog({
        title: 'My Dialog',
        width: 700,
        height: 600,
        closed: true,
        // cache: false,
        modal: true,
        buttons: "#bb"
    })

    //将工具栏所有的函数集合在一个对象中
    var cmdObj;
    cmdObj = {
        //刷新emp页面
        reload: function () {
            $('#dg').datagrid("load")
        }
        ,
        //高级查询
        query: function () {
            var keyword = $("#keyword").textbox("getValue");
            $('#dg').datagrid('load', {
                keyword: keyword,
            });
        },
        //关闭按钮
        cancel: function () {
            $('#dd').dialog("close")
        },
        add:function () {
            var row = $('#dg').datagrid("getSelected");
            console.log(row)
            if (row == null) {
                $.messager.alert("温馨提示", "请选择一行");
                return;
            }
            $('#ff').form("clear");
            $('#dd').dialog("open")
            $('#dd').dialog("setTitle", "查看保单信息")
            //清除以前的数据
            var totalPrice = row.totalPrice? row.totalPrice : 0 ;
            //总价显示
            $("#showtotalAmount").text(totalPrice);
            //保险年限
            //binbin = row.limitYear;
            var totalAmount = row.limitYear? row.limitYear : 0;
            $("#showlimitYear_input").textbox('setValue', totalAmount);


            //回显
            if (row.car) {
                $("#carId").val(row.car.id);
            }
            $('#ff').form('load', row.car);
            //单号处理回显
            $("#billId").val(row.id);

            //产品机构的的回显
            $.get("/product/queryProductListByBillId?billId=" + row.id,
                function (data) {
                    console.log(data);
                    if (data) {
                        $("#showproductInfo_datagrid").datagrid('loadData', data);
                        $("#agency").combobox('setValue', data[0].orgName);
                    }
                })


            //暂存表中的dategrid
            $('#showproductInfo_datagrid').datagrid({
                url: '',
                height:200,
                fitColumns: true,
                //分页条
                pagination: true,
                // fit:true,
                //工具栏
                toolbar: "#odditem",
                columns: [[
                    {field: 'x', checkbox: true},
                    {field: 'id', title: '编号', hidden: true},
                    {field: 'sn', title: '保险编号', width: 100},
                    {field: 'name', title: '保险产品', width: 100},
                    {field: 'annualfee', title: '保险年费', width: 100}
                ]],
                onSelect: function (index, row) {
                    //双击删除一个
                    deleteindex = index;
                    console.log(1111)
                    console.log(deleteindex)
                    //$('#allPermissions').datagrid('deleteRow', index);

                },
            })

        }
    };

    //调用函数集合对象
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })
})




